/*
 * Created: 2022-09-12 18:54:21
 * Author : 涛涛涛
 */

import React, { FC, useContext, useState } from 'react';
import { View, Text } from '@tarojs/components';
import { styled } from 'linaria/react';
import { useClassName } from '@/utils/index';
import RecordList from '@/pages/HomeSearch/components/RecordList/RecordList';
import Taro from '@tarojs/taro';
import { HomeSearchContext } from '@/pages/HomeSearch/HomeSearchContext';

export interface IProps extends ICompProps {}
HistoryRecord.defaultProps = {} as Partial<IProps>;
function HistoryRecord(props: IProps) {
    const { className, style } = props;
    const localClassName = useClassName('HistoryRecord', className);
    // TODO:当用户搜索的时候,还是需要存储一下搜索的内容到本地.
    const { searchDispatch, searchReducer } = useContext(HomeSearchContext);
    return (
        <RootView className={localClassName} style={style}>
            <RecordList
                isLoading={false}
                title="历史搜索"
                options={searchReducer.historyRecordList}
                onSelect={(text: string) =>
                    searchDispatch({
                        type: 'setKeywords',
                        payload: text,
                    })
                }></RecordList>
        </RootView>
    );
}
export default React.memo(HistoryRecord as FC<IProps>);
const RootView = styled(View)`
    &.HistoryRecord {
    }
`;
